#!/usr/bin/python
# coding:utf-8
__author__ = 'good'
__createday__ = '2015-01-15'

from flask.ext.wtf import Form
from wtforms import TextField, BooleanField, TextAreaField, PasswordField, SelectField
from wtforms.validators import Length, EqualTo, URL, DataRequired,Email
from ..models import User
class LoginForm(Form):
    """登陆"""
    email = TextField('email', validators=[DataRequired(u'不能为空')])
    passwd = PasswordField('passwd', validators=[DataRequired(u'不能为空')])
    remember_me = BooleanField('remember_me', default=False)

class RegisterForm(Form):
    """用户注册"""
    email = TextField('Email Address', [Email(u'请输入正确的Email地址！')])

    def __init__(self, *args, **kwargs):
        Form.__init__(self, *args, **kwargs)

    def validate(self):
        if not Form.validate(self):
            return False
        user = User.query.filter_by(email=self.email.data).first()
        if user != None:
            self.email.errors.append(u'此邮箱已被注册，请直接登录或更换邮箱！')
            return False
        return True

class UserEditForm(Form):
    """编辑用户"""
    nicename = TextField('nicename')
    info = TextAreaField('info', validators=[Length(min=0, max=140)])
    url = TextField('url', validators=[Length(min=0, max=100), URL])
    # role = SelectField('role',choices=[(0,u'普通用户'),(1,u'管理员')],coerce=int)
    # is_locked = SelectField('is_locked',choices=[(0,u'不锁定'),(1,u'锁定')],coerce=int)


class UserChangePwdForm(Form):
    """改变密码"""
    password = PasswordField('New Password', [DataRequired(), EqualTo('confirm', message=u'输入不匹配')])
    confirm = PasswordField('Repeat Password')


